<?php

class McCube_Template_Buffer{

    /** */
    public function openBuffer(){
        if(!ob_start())
            throw new McCube_Exception('Can\'t open the buffer !!');

        return true;
    }

    /** */
    public function closeBuffer(){
        $buffered = ob_get_contents();
		ob_end_clean();

        return $buffered;
    }

    /** */
    public function bufferFile($filename, $varsForBuffer=array()){
        $this->openBuffer();
        extract($varsForBuffer);
		include($filename);

		return $this->closeBuffer();
	}

    /** */
	public function bufferString($string, $varsForBuffer=array()){
        $this->openBuffer();
        extract($varsForBuffer);

		eval('?>'.$string);

		return $this->closeBuffer();
    }
}